package com.dayatang.android.Adapter;

import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dayatang.android.Activity.R;

public class SystemMessageListViewAdapter extends BaseAdapter {
	
	private List<HashMap<String, Object>> listItem;
	private LayoutInflater listContainer;
	
	class ListItemView{
		private TextView titleTextView;
		private TextView releaseDateTextView;
		private TextView contentTextView;
		private TextView organizationNameTextView;
		private TextView thisIdTextView;
		private TextView signReadTextView;
	}
	
	public SystemMessageListViewAdapter(Context context,List<HashMap<String, Object>> listItem) {
		this.listItem = listItem;
		listContainer = LayoutInflater.from(context);   
	}

	public int getCount() {
		return listItem.size();
	}

	public Object getItem(int position) {
		return listItem.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		
		ListItemView  listItemView = null;
		
		if(convertView == null){
			listItemView = new ListItemView();
			convertView = listContainer.inflate(R.layout.system_message_listview_item, null);
			
			listItemView.titleTextView = (TextView)convertView.findViewById(R.id.sm_listview_item_title);
			listItemView.releaseDateTextView = (TextView)convertView.findViewById(R.id.sm_listview_item_releaseDate);
			listItemView.contentTextView = (TextView)convertView.findViewById(R.id.sm_listview_item_content);
			listItemView.organizationNameTextView = (TextView)convertView.findViewById(R.id.sm_listview_item_organizationName);
			listItemView.thisIdTextView = (TextView)convertView.findViewById(R.id.sm_listview_item_thisid);
			listItemView.signReadTextView = (TextView)convertView.findViewById(R.id.sm_listview_item_sign_read);
			
            convertView.setTag(listItemView);    

		}else {    
            listItemView = (ListItemView)convertView.getTag();    
        }  
		
		listItemView.titleTextView.setText((String)listItem.get(position).get("ItemTitle"));
		listItemView.releaseDateTextView.setText((String)listItem.get(position).get("ItemReleaseDate"));
		listItemView.contentTextView.setText((String)listItem.get(position).get("ItemContent"));
		listItemView.organizationNameTextView.setText((String)listItem.get(position).get("ItemOrganizationName"));
		listItemView.thisIdTextView.setText((String)listItem.get(position).get("ItemthisId"));
		listItemView.signReadTextView.setText((String)listItem.get(position).get("ItemSignRead"));
		
		return convertView;
	}

}
